package com.leetcode;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class LeetCode1403 {

    public List<Integer> minSubsequence(int[] nums) {

        Integer[] integers = Arrays.stream(nums).boxed().toArray(Integer[]::new);
        Arrays.sort(integers, Collections.reverseOrder());
        List<Integer> result = new ArrayList<>();
        int arr = 0;
        int sum = 0;
        for (int i = 0; i < integers.length; i++) {
            //计算子序列
            arr += integers[i];
            //计算未包含在该子序列中的各元素之和
            for (int j = i + 1; j < integers.length; j++) {
                sum += integers[j];
            }
            if (arr > sum) {
                for (int j = 0; j <= i; j++) {
                    result.add(integers[j]);
                }
                break;
            }
            sum = 0;
        }
        return result;
    }

    public static void main(String[] args) {

        int[] nums = {4, 6, 4, 4, 8, 5, 1, 7, 9};
        LeetCode1403 leetCode1403 = new LeetCode1403();
        List<Integer> integerList = leetCode1403.minSubsequence(nums);
        System.out.println(integerList);

    }

}
